﻿using System;
using System.Collections.Generic;

namespace WebApplication1.classes.Core.Chrome.Bookmarks.Model {
    public class ChromeBookmark {
        public ChromeBookmark() {
            children = new List<ChromeBookmark>();
        }

        public IList<ChromeBookmark> children { get; set; }

        public string date_added { get; set; }

        public string date_modified { get; set; }

        public string id { get; set; }

        public string name { get; set; }

        public string type { get; set; }

        public string url { get; set; }

        public virtual String identifier() {
            return String.Format("<{0}:{1}>", new object[] { GetType().Name, id });//i.e. <ChromeBookmark:12>
        }

        public virtual ChromeBookmark onChildCopy( ChromeBookmark child) {
            return child.copy();
        }

        private void fassignChildrenTo( ChromeBookmark item) {
            item.children.Clear();
            foreach ( ChromeBookmark child in children ) {
                ChromeBookmark childCopy = onChildCopy( child);
                item.children.Add( childCopy );
            }
        }

        public virtual void assignTo(ChromeBookmark item)
        {
            if ( item == null ) {
                return;
            }

            item.date_added = date_added;
            item.date_modified = date_modified;
            item.id = id;
            item.name = name;
            item.type = type;
            item.url = url;
            item.children.Clear();
            fassignChildrenTo( item);
        }

        public virtual ChromeBookmark copy() {
            var result = new ChromeBookmark();
            assignTo( result);
            return result;
        }
    }
}